package com.reform.controller.common;

import com.reform.pojo.teacher.Teacher;
import com.reform.res.Result;
import com.reform.service.ITeacherService;
import com.reform.service.MailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.SQLException;

@Api(tags = "InitController")
@RestController
@RequestMapping("/init")
public class InitController {

    @Autowired
    ITeacherService teacherService;
    @Autowired
    MailService mailService;

    @ApiOperation(value = "初始化账号",notes = "初始化账号")
    @PostMapping("/index")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "gh",value = "工号",paramType = "query",dataTypeClass = String.class,required = true),
            @ApiImplicitParam(name = "password",value = "密码",paramType = "query",dataTypeClass = String.class,required = true),
            @ApiImplicitParam(name = "email",value = "邮箱",paramType = "query",dataTypeClass = String.class,required = true),
            @ApiImplicitParam(name = "type",value = "类型",paramType = "query",dataTypeClass = Integer.class,required = true),
    })
    public Result init(Teacher teacher) throws SQLException {
        return teacherService.init(teacher);
    }

    @ApiOperation(value = "初始化所有账号",notes = "初始化所有账号")
    @PostMapping("/initAll")
    @ApiImplicitParams({
    })
    public Result initAll() throws SQLException {
        return teacherService.initAll();
    }

    @ApiOperation(value = "获取邮箱验证码",notes = "获取邮箱验证码")
    @PostMapping("/sendEmailCode")
    @ApiImplicitParam(name = "email",value = "邮箱",paramType = "query",dataTypeClass = String.class,required = true)
    public Result sendEmailCode(String email){
        return mailService.sendVertifyCode(email);
    }

    @ApiOperation(value = "验证邮箱验证码",notes = "验证邮箱验证码")
    @PostMapping("/vertifyEmailCode")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "email",value = "邮箱",paramType = "query",dataTypeClass = String.class,required = true),
            @ApiImplicitParam(name = "code",value = "验证码",paramType = "query",dataTypeClass = String.class,required = true),
    })
    public Result vertifyEmailCode(String email,String code){
        return mailService.vertifyCode(email,code);
    }

}
